#pragma once
#include "string"

#include "ObjectDetector.h"
#include <opencv2/opencv.hpp>

using namespace std;

class YangsFingerRootsDetector : virtual public ObjectDetector
{
private:
  cv::Mat img;
  cv::Mat detected_result;
  cv::Mat gray_tmp;
  //finger roots [x1,y1,x2,y2,x3,y3]
  int fingerConner[6];
  bool isLeftHand = false;

  vector<cv::Point> getCornerPoints();
  bool detectLR();
  void findFingerRoots(vector<cv::Point> candidator);
  float distance(cv::Point a, cv::Point b);
  void draw_candidators(vector<cv::Point> candidator, cv::Scalar color);

  vector<cv::Point> filterFingerRoots_Template(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_aggregate(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_position(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_KMeans(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_PCA(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_yvalue(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_xvalue(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_distance(vector<cv::Point> candidator);
  vector<cv::Point> filterFingerRoots_Tangent(vector<cv::Point> candidator);

public:
  YangsFingerRootsDetector(cv::Mat &img);
  ~YangsFingerRootsDetector();
  ObjectDetector *detect();
  cv::Mat getResult() { return detected_result; };
  int getDetectedArr(int *result);
};